<?php
/**
 * ----------------------------------------------------------
 * date: 2019/6/10 8:42
 * ----------------------------------------------------------
 * author: Raoxiaoya
 * ----------------------------------------------------------
 * describe: 记录请求日志
 * ----------------------------------------------------------
 */

namespace App\Http\Middleware;


use Closure;
use App\Service\Log\LogFile;
use Illuminate\Support\Facades\Log;

class RequestLog
{

    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure $next
     *
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        try{
            $logger = new LogFile();
            //$param  = [$request->header(), $request->input()];
            //$logger->info('Request | '.$request->getPathInfo().' |', $param);
            $logger->write($request->getPathInfo(), 'HOST');
            //$logger->write($request->header(), 'header');
            $logger->write($request->input(), 'param');


            return $next($request);
        } catch(HttpException $e){
            return ['code' => $e->getStatusCode(), 'msg' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()];
        } catch(\Exception $e){
            return ['code' => 1, 'msg' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()];
        }
    }
}


